#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>

int main()
{
    pid_t pid = fork();
    if (pid < 0)
    {
        fprintf(stderr, "fork error!\n");
        exit(-1);
    }
    else if (pid == 0)
    {
        /*子进程*/
        printf("%d : child is running.\n", getpid());
        exit(120);
    }
    else
    {
        /*父进程*/
        int s;
        pid_t t;
        t = wait(&s);
        /*WEXITSTATUS(s) 这个宏可以获取子进程退出码*/
        printf("waiting for %d status %d\n", t, WEXITSTATUS(s));
        return 0;
    }
}